﻿
#pragma execution_character_set("utf-8")
// 本文件为utf-8 编码格式

#include "FirstViewController.h"
#include "ViewController/ImageFilterViewController.h"
#include "Util/GDUtil.h"
#include "ViewController/GdChatViewController.h"
#include "ViewController/RoundImageViewController.h"
#include "ViewController/ImageStickerViewController.h"

FirstViewController::FirstViewController()
{

}

FirstViewController::~FirstViewController()
{

}

void FirstViewController::viewDidLoad()
{
	

    // Do any additional setup after loading the view from its nib.
	CCSize winSize = this->getView()->getBounds().size;
    
	scrollView = CAScrollView::createWithFrame(this->getView()->getBounds());
	scrollView->setBounceHorizontal(false);
	scrollView->setBounceVertical(false);
	scrollView->setHorizontalScrollEnabled(false);
	scrollView->setShowsHorizontalScrollIndicator(false);
	scrollView->setShowsVerticalScrollIndicator(false);
	this->getView()->addSubview(scrollView);

	scrollView->addSubview(GDUtil::createLabelWithFrame(CCRect(0, 0, winSize.width, _px(60)), "源码地址： http://git.oschina.net/geelou/BeautifulJelly"));

	CAButton *btn = CAButton::createWithFrame(CCRect(_px(20), _px(60), winSize.width - _px(40), _px(40)), CAButtonTypeRoundedRect);
	btn->setTextTag("imagefilter");
	btn->setTitleForState(CAControlStateAll, "图片滤镜功能");
	btn->addTarget(this, CAControl_selector(FirstViewController::onBtnClick), CAControlEventTouchUpInSide);
	scrollView->addSubview(btn);

	btn = CAButton::createWithFrame(CCRect(_px(20), btn->getFrameOrigin().y + btn->getBounds().size.height+ _px(20), winSize.width - _px(40), _px(40)), CAButtonTypeRoundedRect);
	btn->setTextTag("chat");
	btn->setTitleForState(CAControlStateAll, "与智能机器人聊天");
	btn->addTarget(this, CAControl_selector(FirstViewController::onBtnClick), CAControlEventTouchUpInSide);
	scrollView->addSubview(btn);

	btn = CAButton::createWithFrame(CCRect(_px(20), btn->getFrameOrigin().y + btn->getBounds().size.height + _px(20), winSize.width - _px(40), _px(40)), CAButtonTypeRoundedRect);
	btn->setTextTag("roundImage");
	btn->setTitleForState(CAControlStateAll, "圆形图片");
	btn->addTarget(this, CAControl_selector(FirstViewController::onBtnClick), CAControlEventTouchUpInSide);
	scrollView->addSubview(btn);

	btn = CAButton::createWithFrame(CCRect(_px(20), btn->getFrameOrigin().y + btn->getBounds().size.height + _px(20), winSize.width - _px(40), _px(40)), CAButtonTypeRoundedRect);
	btn->setTextTag("imageSticker");
	btn->setTitleForState(CAControlStateAll, "图片旋转缩放");
	btn->addTarget(this, CAControl_selector(FirstViewController::onBtnClick), CAControlEventTouchUpInSide);
	scrollView->addSubview(btn);


	float height = btn->getFrameOrigin().y + btn->getBounds().size.height + _px(20);
	if (height > winSize.height){
		scrollView->setViewSize(CCSize(winSize.width, height));
	}
}

void FirstViewController::viewDidUnload()
{
    
}

void FirstViewController::onBtnClick(CrossApp::CAControl *control, CrossApp::CCPoint point)
{
	std::string textTag = control->getTextTag();

	if (textTag == "imagefilter")
	{
		ImageFilterViewController *viewControl = new ImageFilterViewController();
		viewControl->setNavigationBarItem(CANavigationBarItem::create("图片滤镜"));
		GDUtil::pushViewController(viewControl);
	}
	else if (textTag == "chat")
	{
		GdChatViewController *viewControl = new GdChatViewController();
		viewControl->setNavigationBarItem(CANavigationBarItem::create("与智能机器人聊天"));
		GDUtil::pushViewController(viewControl);
	}
	else if (textTag == "roundImage")
	{
		RoundImageViewController *viewControl = new RoundImageViewController();
		viewControl->setNavigationBarItem(CANavigationBarItem::create("圆形图片"));
		GDUtil::pushViewController(viewControl);
	}
	else if (textTag == "imageSticker")
	{
		ImageStickerViewController *viewControl = new ImageStickerViewController();
		viewControl->setNavigationBarItem(CANavigationBarItem::create("图片旋转缩放拖动"));
		GDUtil::pushViewController(viewControl);
	}
}